#include <GL/glut.h>
#include "Input.h"
#include "Configuration.h"

Key PlayerInput::P1_DOWN;
Key PlayerInput::P1_FIRE;
Key PlayerInput::P1_LEFT;
Key PlayerInput::P1_RIGHT;
Key PlayerInput::P1_UP;
Key PlayerInput::P1_TIME_WARP;

void PlayerInput::LoadKeySettings()
{
	//temporary solution , it will be loaded from input configuration file in the future.

	P1_UP.Value = 'w';
	P1_UP.IsPressed = false;
	P1_DOWN.Value = 's';
	P1_DOWN.IsPressed = false;
	P1_LEFT.Value = 'a';
	P1_LEFT.IsPressed = false;
	P1_RIGHT.Value = 'd';
	P1_RIGHT.IsPressed = false;
	P1_FIRE.Value = 'l';
	P1_FIRE.IsPressed = false;

}

void PlayerInput::KeyDown (unsigned char key,int x, int y)
{
		if (P1_UP.Value == key) 
			P1_UP.IsPressed= true;
		if (P1_DOWN.Value == key)
			P1_DOWN.IsPressed=true;
		if (P1_LEFT.Value == key)
			P1_LEFT.IsPressed=true;
		if (P1_RIGHT.Value == key)
			P1_RIGHT.IsPressed=true;
		if (P1_FIRE.Value == key)
			P1_FIRE.IsPressed=true;
		// exit on ESC
		if (27 == key)
		{
			if(Config::Fullscreen)
				glutLeaveGameMode();
			exit(0);
		}
}

void PlayerInput::KeyUp (unsigned char key,int x, int y)
{
	if (P1_UP.Value == key) 
			P1_UP.IsPressed= false;
		if (P1_DOWN.Value == key)
			P1_DOWN.IsPressed=false;
		if (P1_LEFT.Value == key)
			P1_LEFT.IsPressed=false;
		if (P1_RIGHT.Value == key)
			P1_RIGHT.IsPressed=false;
		if (P1_FIRE.Value == key)
			P1_FIRE.IsPressed=false;
}